<template>
  <!-- 门票详情自营商品弹出框 -->
  <view v-show="hideModal" class="container">
    <view class="mask" catchtouchmove="ture" @touchmove.stop.prevent @click.stop="close()" />
    <view
      :class="devtools==='ios' ?'content-ios bottom-pos':'content bottom-pos'"
      :animation="animationData"
      @touchmove.stop.prevent
    >
      <!-- 选择日期 -->
      <view class="choice-date">
        <!-- 头部，关闭部分 -->
        <view class="choice-date-head">
          <text>选择日期</text>
          <image src="@/static/image/default/contacts/close.png" @click.stop="close()" />
        </view>
        <!-- 引入日历 -->
        <uniCalendar
          v-if="dateList"
          :my-data="dateList"
          :insert="true"
          :lunar="true"
          :show-month="false"
          :date="datetime"
          @change="change"
        />
      </view>
    </view>
  </view>
</template>

<script>
import { get } from '@utils/storage'
import uniCalendar from '@com/uni-calendar/uni-calendar'
import { getSelfProductPackage } from '@/api/self'
import { extractionAnimation } from '@utils/myApproach'
export default {
  components: { uniCalendar },
  props: {
    show: {
      type: Boolean,
      required: true
    },
    datetime: {
      type: String,
      default: null
    },
    uid: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      hideModal: false, // 模态框的状态  true-隐藏  false-显示
      animationData: {}, //
      val: 0,
      dateList: null,
      routeName: null,
      packageUid: null
    }
  },
  computed: {
    devtools() {
      return get('devtools')
    }
  },
  watch: {
    show(val) {
      if (val) {
        this.showModal()
      }
    }
  },
  methods: {
    // 显示遮罩层
    showModal: function() {
      var that = this
      that.hideModal = true
      this.animation = extractionAnimation()
      getSelfProductPackage(this.uid).then(res => {
        this.dateList = res.data.data
      })

      setTimeout(function() {
        that.fadeIn() // 调用显示动画
      }, 50)
    },
    // 隐藏遮罩层
    close: function() {
      var that = this
      this.animation = extractionAnimation()
      this.dateList = null
      that.fadeDown() // 调用隐藏动画
      setTimeout(function() {
        that.hideModal = false
        that.$emit('close', !that.show)
      }, 50) // 先执行下滑动画，再隐藏模块
    },
    // 动画集
    fadeIn: function() {
      this.animation.translateY(0).step()
      this.animationData = this.animation.export() // 动画实例的export方法导出动画数据传递给组件的animation属性
    },
    fadeDown: function() {
      if (this.devtools === 'ios') {
        this.animation.translateY(1006).step()
      } else {
        this.animation.translateY(940).step()
      }
      this.animationData = this.animation.export()
    },
    change(date) {
      this.$emit('changeDate', date.fulldate)
      this.close()
    }
  }
}
</script>
<style >
.mask {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  position: fixed;
  top: 0;
  left: 0;
}
.content {
  width: 750rpx;
  height: 940rpx;
  position: fixed;
  bottom: 0;
  left: 0;
  background-color: #ffffff;
  z-index: 1000;
  border-radius: 20rpx 20rpx 0 0;
  overflow: hidden;
}
.content-ios {
  width: 750rpx;
  height: 1006rpx;
  position: fixed;
  bottom: 0;
  left: 0;
  background-color: #ffffff;
  z-index: 1000;
  border-radius: 20rpx 20rpx 0 0;
  overflow: hidden;
}
/*动画前初始位置*/
.bottom-pos {
  -webkit-transform: translateY(100%);
  transform: translateY(100%);
}
</style>
<style scoped >
.self-ticket {
  display: flex;
  width: 1500rpx;
  position: absolute;
  height: 100%;
  transition: all 0.4s;
}
.choice-date-text {
  display: flex;
  font-size: 28rpx;
  color: #306de9;
}
.choice-date-text > text {
  margin-left: 30rpx;
}
.choice-date-text > image {
  width: 32rpx;
  height: 32rpx;
  margin-left: 16rpx;
  margin-top: 5rpx;
}
</style>
<style scoped>
/* 选择日期*/
.choice-date {
  width: 750rpx;
  height: 100%;
  overflow: hidden;
}
.choice-date-head {
  display: flex;
  justify-content: space-between;
  margin-top: 40rpx;
  margin-bottom: 50rpx;
}
.choice-date-head > text {
  font-size: 32rpx;
  color: #000000;
  font-weight: 400;
  margin-left: 30rpx;
}
.choice-date-head > image {
  width: 32rpx;
  height: 32rpx;
  margin-right: 30rpx;
  margin-top: 6rpx;
}
</style>
